import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 验证IP地址
     * @param IP string字符串 一个IP地址字符串
     * @return string字符串
     */
    public String solve (String IP) {
        Boolean isIPV4 = false;
        for (int i = 0; i < IP.length(); i++) {
            if (IP.charAt(i) == '.') {
                isIPV4 = true;
                break;
            } else if (IP.charAt(i) == ':') {//要写成else if，不要写成else,因为写成else判断则判断第一个字符不为.则会直接跳出循环导致isIPV4==false
                break;
            }
        }

        if (isIPV4) {
            //一共五步判断
            String[] arr1 = IP.split("\\.", -1);
            if (arr1.length != 4) return "Neither";
            for (int i = 0; i < arr1.length; i++) {
                if (arr1[i].length() == 0) {
                    return "Neither";
                }
                for (int j = 0; j < arr1[i].length(); j++) {//注意不要写成i++
                    if (arr1[i].charAt(j) > '9' || arr1[i].charAt(j) < '0') {
                        return "Neither";
                    }
                }
                if (Integer.parseInt(arr1[i]) > 255) {
                    return "Neither";
                }
                if (arr1[i].length() != 1 && arr1[i].charAt(0) == '0') {//注意不要写成charAt(i)
                    return "Neither";
                }
            }
            return "IPv4";//这一步要写到上面的for循环外
        }else {
            //一共五步判断
            String[] arr2 = IP.split("\\:", -1);
            if (arr2.length != 8) return "Neither";
            for (int i = 0; i < arr2.length; i++) {

                if (!arr2[i].equals("0")) {
                    if (arr2[i].length() != 4) {
                        return "Neither";
                    }
                    if (arr2[i].equals("0000")) {
                        return "Neither";
                    }
                    for (int j = 0; j < arr2[i].length(); j++) {//不要写成j++
                        boolean exp = (arr2[i].charAt(j) <= '9' && arr2[i].charAt(j) >= '0') || (arr2[i].charAt(j) <= 'f' && arr2[i].charAt(j) >= 'a'
                                || (arr2[i].charAt(j) <= 'F' && arr2[i].charAt(j) >= 'A'
                        ));//注意这个判断条件是这样写,要有|| (arr2[i].charAt(j) <= 'F' && arr2[i].charAt(j) >= 'A'，因为不区分大小写

                        if (!exp) {
                            return "Neither";
                        }
                    }
                }
            }
            return "IPv6";
        }
    }
}




    class Main {
    public static void main(String[] args) {
        Solution solution = new Solution();
        String IP = "2001:db8:85a3:0::8a2E:0370:7334";
        System.out.println(solution.solve(IP));
    }
}


